/*
 * @Author: xiaosihan 
 * @Date: 2024-07-29 12:22:45 
 * @Last Modified by: 肖思汗
 * @Last Modified time: 2025-05-23 14:08:51
 */

import { STS } from "ali-oss";
import express from "express";
import database from "../database";
import ServiceBase from "./ServiceBase";

import FacebodyClient from "@alicloud/facebody20191230";


// 视觉智能开放平台
class VisualPlatformServer extends ServiceBase {

    constructor() {
        super();
        this.anime();
    }


    // 人像动漫
    // anime = async (req: express.Request, res: express.Response, next: express.NextFunction) => {
    // const { imageURL } = this.getParame(req);
    anime = async () => {

        // 填写步骤1创建的RAM用户AccessKey
        let sts = new STS({
            accessKeyId: "LTAI5tDvQxyQZe9Lx1TrePpZ",
            accessKeySecret: "3LQypxiCxStfPltYkk5ulLrTCFWVrB",
        });
        // roleArn填写步骤2获取的角色ARN，例如acs:ram::175708322470****:role/ramtest。
        // policy填写自定义权限策略，用于进一步限制STS临时访问凭证的权限。如果不指定Policy，则返回的STS临时访问凭证默认拥有指定角色的所有权限。
        // 临时访问凭证最后获得的权限是步骤4设置的角色权限和该Policy设置权限的交集。
        // expiration用于设置临时访问凭证有效时间单位为秒，最小值为900，最大值以当前角色设定的最大会话时间为准。本示例指定有效时间为3000秒。
        // sessionName用于自定义角色会话名称，用来区分不同的令牌，例如填写为sessiontest。
        const token = await sts.assumeRole('acs:ram::1348366854007839:role/aliyun-ai', ``, 3000, 'sessiontest');

        // console.log(token.credentials);

        const client = new FacebodyClient({
            toMap: () => {
                return {}
            },
            regionId: "cn-shanghai",
            accessKeyId: token.credentials.AccessKeyId,
            accessKeySecret: token.credentials.AccessKeySecret,
            securityToken: token.credentials.SecurityToken,

        });

        // anime：日漫风  3d：3D特效 handdrawn：手绘风 sketch：铅笔画 artstyle：艺术特效 claborate ：国画工笔画 hongkong ：港漫风 comic：漫画风格 animation3d：动画3D
        //  AlgoType
        await client.generateHumanAnimeStyle({
            algoType: "anime",
            imageURL: "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/GenerateHumanAnimeStyle/GenerateHumanAnimeStyle8.png",
            // imageURL: "https://ut-p.oss-cn-shanghai.aliyuncs.com/img/03229c0e-a364-4c41-9234-71b2385cb018-test.png?x-oss-credential=LTAI5tPwjzeo6xVv9ytGdex5%2F20250523%2Fcn-shanghai%2Foss%2Faliyun_v4_request&x-oss-date=20250523T064934Z&x-oss-expires=3600&x-oss-signature-version=OSS4-HMAC-SHA256&x-oss-signature=7fb9875d7a78e78ba29055dad021abbab25a985c908ae320a2b17e4dc304993e",
            // imageURL: imageURL,
            toMap: () => {
                return {}
            },

        }).then(res => {
            //@ts-ignore
            console.log(res.body.data.imageURL);
        }).catch(err => {
            console.log(err.data);
        })

        await client.generateHumanAnimeStyle({
            algoType: "anime",
            // imageURL: "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/GenerateHumanAnimeStyle/GenerateHumanAnimeStyle8.png",
            imageURL: "https://ut-p.oss-cn-shanghai.aliyuncs.com/img/03229c0e-a364-4c41-9234-71b2385cb018-test.png?x-oss-credential=LTAI5tPwjzeo6xVv9ytGdex5%2F20250523%2Fcn-shanghai%2Foss%2Faliyun_v4_request&x-oss-date=20250523T064934Z&x-oss-expires=3600&x-oss-signature-version=OSS4-HMAC-SHA256&x-oss-signature=7fb9875d7a78e78ba29055dad021abbab25a985c908ae320a2b17e4dc304993e",
            // imageURL: imageURL,
            toMap: () => {
                return {}
            },

        }).then(res => {
            //@ts-ignore
            console.log(res.body.data.imageURL);
        }).catch(err => {
            console.log(err.data);
        })


    }



}

const visualPlatformServer = new VisualPlatformServer();

export default visualPlatformServer;